package io.renren.modules.generator.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.generator.dao.GoodsDao;
import io.renren.modules.generator.entity.GoodsEntity;
import io.renren.modules.generator.service.GoodsService;


@Service("goodsService")
public class GoodsServiceImpl extends ServiceImpl<GoodsDao, GoodsEntity> implements GoodsService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<GoodsEntity> page = this.selectPage(
                new Query<GoodsEntity>(params).getPage(),
                new EntityWrapper<GoodsEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils queryGoodsByPrice(Map<String, Object> params) {
        List<GoodsEntity> list = baseMapper.goodsByPrice();
        Page<GoodsEntity> page = new Page<GoodsEntity>();
        page.setRecords(list);
        page.setCondition(params);
        page.setTotal(list.size());
        System.out.println("page = " + page);
        return new PageUtils(page);
    }

    @Override
    public List<GoodsEntity> getByKey(Object key) {
        List<GoodsEntity> list = baseMapper.goodsByKey(key);

        return list;
    }
}
